package com.sanjiahantang.youjiaclient.module.common.views.impl;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.uilibrary.popuwindow.SelectPhotoPopupwindow;
import com.sanjiahantang.uilibrary.utils.BitmapUtils;
import com.sanjiahantang.uilibrary.utils.ImageUtils;
import com.sanjiahantang.uilibrary.utils.QRCodeUtil;
import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.uilibrary.views.CircleImageView;
import com.sanjiahantang.uilibrary.views.GridViewFixScroll;
import com.sanjiahantang.uilibrary.views.ObservableScrollView;
import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpFragment;
import com.sanjiahantang.youjiaclient.config.ConfigValue;
import com.sanjiahantang.youjiaclient.config.SPConfig;
import com.sanjiahantang.youjiaclient.module.common.beans.FileBean;
import com.sanjiahantang.youjiaclient.module.common.beans.MeIcon;
import com.sanjiahantang.youjiaclient.module.common.beans.MessageNoticeCountBean;
import com.sanjiahantang.youjiaclient.module.common.presenters.MePresenter;
import com.sanjiahantang.youjiaclient.module.common.views.MeView;
import com.sanjiahantang.youjiaclient.module.login.views.impl.LoginActivity;
import com.sanjiahantang.youjiaclient.module.me.order.views.OrderView;
import com.sanjiahantang.youjiaclient.module.me.order.views.impl.MyOrderActivity;
import com.sanjiahantang.youjiaclient.utils.FileUtils;
import com.sanjiahantang.youjiaclient.utils.SPUtils;
import com.squareup.picasso.Picasso;

import java.io.File;

import q.rorbin.badgeview.QBadgeView;

import static com.sanjiahantang.uilibrary.utils.Utils.checkIsVisible;


/**
 * 个人中心
 */
public class MeFragment extends BaseMvpFragment<MeView, MePresenter> implements MeView, View.OnClickListener, AdapterView.OnItemClickListener, ObservableScrollView.OnScrollChangedListener {
    private CircleImageView headPhoto;
    private View lineLay_not_login, mainTitle, titleView,txtQR;
    private RelativeLayout lineLay_login;
    private RelativeLayout rl_CSD;
    private RelativeLayout rl_evaluate;
    private RelativeLayout rl_helpCenter;
    private RelativeLayout rl_lineSettings;//设置键
    private LinearLayout ll_detail;
    private TextView txtNickname;
    private GridViewFixScroll gridView;
    private QBadgeView messageQbv,titleMessageQbv;
    private View mView;
    private ObservableScrollView scrollView;
    private SelectPhotoPopupwindow photoPopupwindow;
    final int PHOTO_GRAPH = 0xF, SELECT_PICTURE = 3, INTENT_NICKNAME = 5, SAVE_PHOTO = 6;
    public static String filePath = "";
    private Uri imageUri;
    private RadioButton rbGoods;
    private String filed_id;
//    QBadgeView qqq;

    protected static final int CHOOSE_PICTURE = 0;
    protected static final int TAKE_PICTURE = 1;
    protected static Uri tempUri;
    private static final int CROP_SMALL_PICTURE = 2;
    private static final int UPLOAD_PIC = 3;

    private Bitmap mBitmap;

    private int[] orderTypes = new int[]{
            OrderView.TYPE_UN_PAY,
            OrderView.TYPE_PART_PAY,
            OrderView.TYPE_PAYED,
            OrderView.TYPE_COMPLETE,

    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (mView != null) {
            ViewGroup parent = (ViewGroup) mView.getParent();
            if (parent != null) {
                parent.removeView(mView);
            }
        } else {
            mView = inflater.inflate(R.layout.fragment_me, container, false);
        }
        return mView;
    }


    @Override
    protected void initView() {
        mView.findViewById(R.id.titleView).setVisibility(View.GONE);
        gridView = (GridViewFixScroll) mView.findViewById(R.id.gridview);

        lineLay_not_login = mView.findViewById(R.id.lineLay_not_login);
        lineLay_login = (RelativeLayout) mView.findViewById(R.id.lineLay_login);
        mainTitle = mView.findViewById(R.id.mainTitle);
        titleView = mView.findViewById(R.id.titleView);
//        rl_leavemsg= (RelativeLayout) mView.findViewById(R.id.layout_message);
        rl_helpCenter = (RelativeLayout) mView.findViewById(R.id.helpCenter);
        rl_evaluate = (RelativeLayout) mView.findViewById(R.id.layout_evaluate);
        ll_detail = (LinearLayout) mView.findViewById(R.id.ll_my_detail);
        rl_lineSettings = (RelativeLayout) mView.findViewById(R.id.lineSettings);
        headPhoto = (CircleImageView) mView.findViewById(R.id.imgHead);
        txtNickname = (TextView) mView.findViewById(R.id.txtNickname);
        scrollView = (ObservableScrollView) mView.findViewById(R.id.scrollView);
        txtQR = mView.findViewById(R.id.txtQR);

//        messagePointImg=mView.findViewById(R.id.ivPoint);

        messageQbv = new QBadgeView(context);
        messageQbv.bindTarget(mView.findViewById(R.id.F_right)).setBadgeGravity(Gravity.TOP | Gravity.END);
        messageQbv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                presenter.goMessagePage(context);
            }
        });
        mView.findViewById(R.id.txtLogin).setOnClickListener(this);
        mView.findViewById(R.id.txtRegister).setOnClickListener(this);
        mView.findViewById(R.id.rlOrder).setOnClickListener(this);
//        mView.findViewById(R.id.F_right).setOnClickListener(this);
        mView.findViewById(R.id.decorateManager).setOnClickListener(this);
        mView.findViewById(R.id.require).setOnClickListener(this);
        mView.findViewById(R.id.scheme).setOnClickListener(this);
        mView.findViewById(R.id.rlFavorite).setOnClickListener(this);
        mView.findViewById(R.id.layout_contract).setOnClickListener(this);
        mView.findViewById(R.id.lineLay_login).setOnClickListener(this);

        rl_CSD = (RelativeLayout) mView.findViewById(R.id.rl_CSD);
        rl_CSD.setOnClickListener(this);
        rl_evaluate.setOnClickListener(this);
        rl_helpCenter.setOnClickListener(this);
        rl_lineSettings.setOnClickListener(this);
        txtQR.setOnClickListener(this);

        gridView.setAdapter(presenter.initGridAdapter(context));
        gridView.setOnItemClickListener(this);

        scrollView.setOnScrollChangedListener(this);


        TextView title = (TextView) titleView.findViewById(R.id.title);
        title.setText("我的");
//        titleMessageFrame=titleView.findViewById(R.id.flIcon1);
        titleMessageQbv = new QBadgeView(context);
        titleMessageQbv.bindTarget(mView.findViewById(R.id.flIcon1)).setBadgeGravity(Gravity.TOP | Gravity.END);
        titleMessageQbv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                presenter.goMessagePage(context);
            }
        });
        showRightButton(R.drawable.i_ring).setOnClickListener(this);
        photoPopupwindow = new SelectPhotoPopupwindow(context, this);


        rbGoods = (RadioButton) mView.findViewById(R.id.rbGoods);
    }


    @Override
    protected void initData() {
        if(TextUtils.isEmpty(ConfigValue.DATA_KEY)){
            Intent intent=new Intent(context, LoginActivity.class);
            startActivityForResult(intent,ME_FRAGMENT);
        }
    }

    @Override
    public void startActivityForResult(Intent intent, int requestCode) {
        super.startActivityForResult(intent, requestCode);
    }

    @Override
    public void onResume() {
        super.onResume();
        if (presenter.network(context)){
            presenter.onLoad(context);
            if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)){
                presenter.getSearchNoticeCountForCustomer(context, new OnLoadListener() {
                    @Override
                    public void onLoad(Object content) {
                        if (content != null && content instanceof MessageNoticeCountBean.Data){
                            try {
                                MessageNoticeCountBean.Data data = (MessageNoticeCountBean.Data) content;
                                if (data.getNum() > 0) {
                                    messageQbv.setBadgeText(String.valueOf(data.getNum()))
                                            .setGravityOffset(2, 2, true)
                                            .setBadgeTextSize(8, true);

                                    titleMessageQbv.setBadgeText(String.valueOf(data.getNum()))
                                            .setGravityOffset(2, 2, true)
                                            .setBadgeTextSize(8, true);
                                } else {
                                    messageQbv.setBadgeText(String.valueOf(data.getNum()))
                                            .setGravityOffset(2, 2, true)
                                            .setBadgeTextSize(8, true)
                                            .hide(false);

                                    titleMessageQbv.setBadgeText(String.valueOf(data.getNum()))
                                            .setGravityOffset(2, 2, true)
                                            .setBadgeTextSize(8, true)
                                            .hide(false);
                                }
                            }catch (Exception e){
                                messageQbv.setBadgeText(String.valueOf(0))
                                        .setGravityOffset(2, 2, true)
                                        .setBadgeTextSize(8, true)
                                        .hide(false);

                                titleMessageQbv.setBadgeText(String.valueOf(0))
                                        .setGravityOffset(2, 2, true)
                                        .setBadgeTextSize(8, true)
                                        .hide(false);
                            }
                        }else{
                            messageQbv.setBadgeText(String.valueOf(0))
                                    .setGravityOffset(2, 2, true)
                                    .setBadgeTextSize(8, true)
                                    .hide(false);

                            titleMessageQbv.setBadgeText(String.valueOf(0))
                                    .setGravityOffset(2, 2, true)
                                    .setBadgeTextSize(8, true)
                                    .hide(false);
                        }
                    }
                });

            }else {
                messageQbv.setBadgeText(String.valueOf(0))
                        .setGravityOffset(2, 2, true)
                        .setBadgeTextSize(8, true)
                        .hide(false);

                titleMessageQbv.setBadgeText(String.valueOf(0))
                        .setGravityOffset(2, 2, true)
                        .setBadgeTextSize(8, true)
                        .hide(false);

            }
        }


    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        presenter.onItemClick(context, rbGoods.isChecked() ? 1 : 2, orderTypes[position]);
    }


    @Override
    public void onClick(View v) {
        if (!presenter.network(context)){
            return;
        }
        switch (v.getId()) {
//            //消息
//            case R.id.F_right:
//            case R.id.flIcon1:
//                presenter.goMessagePage(context);
//                break;
            //我的账户
            case R.id.lineLay_login:
                photoPopupwindow.showAtLocation(mView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                break;
            //登陆
            case R.id.txtLogin:
                presenter.toLogin(context);
                break;
            //注册
            case R.id.txtRegister:
                presenter.goRegisterPage(context);
                break;
            //装修管理
            case R.id.decorateManager:
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    presenter.goDecorateManagerPage(context);
                } else {
                    LoginActivity.logout(context);
                }
                break;
            //帮助中心
            case R.id.helpCenter:
                presenter.goHelpCenter(context);
                break;
            case R.id.require://我的需求
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    presenter.goRequirePage(context);
                } else {
                    startActivity(new Intent(context, LoginActivity.class));
                }

                break;
            //方案
            case R.id.scheme:
            //    startActivity(new Intent(context, ProgramPriceActivity.class));
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    presenter.goSchemePage(context);
                } else {
                    LoginActivity.logout(context);
                }

                break;
            //全部订单
            case R.id.rlOrder:
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    Intent intent = new Intent(context,MyOrderActivity.class);
                    intent.putExtra("type1",rbGoods.isChecked() ? 1 : 2);
                    intent.putExtra("type2",OrderView.TYPE_ALL);
                    context.startActivity(intent);
                } else {
                    startActivity(new Intent(context, LoginActivity.class));
                }
                break;
            //收藏
            case R.id.rlFavorite:
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    presenter.goFavoritePage(context);
                } else {
                    LoginActivity.logout(context);
                }
                break;
            //合同
            case R.id.layout_contract:
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    presenter.goContractPage(context);
                } else {
                    startActivity(new Intent(context, LoginActivity.class));
                }
                break;
            //评价
            case R.id.layout_evaluate:
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    presenter.goEvaluatePage(context);
                } else {
                    LoginActivity.logout(context);
                }
                break;
            //设置
            case R.id.lineSettings:
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    presenter.goSettingsPage(context);
                } else {
                    startActivity(new Intent(context, LoginActivity.class));
                }
                break;
            //客服与投诉
            case R.id.rl_CSD:
                if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)) {
                    presenter.goCSDPage(context);
                } else {
                    LoginActivity.logout(context);
                }
                break;
            //拍照
            case R.id.btn_take_photo:
                photoPopupwindow.dismiss();
                if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        requestPermissions(new String[]{Manifest.permission.CAMERA}, 1);
                    }
                } else {
//                    Intent openCameraIntent = new Intent(
//                            MediaStore.ACTION_IMAGE_CAPTURE);
//                    tempUri = Uri.fromFile(new File(Environment
//                            .getExternalStorageDirectory(), "head.jpg"));
//                    // 将拍照所得的相片保存到SD卡根目录
//                    openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
//                    startActivityForResult(openCameraIntent, UPLOAD_PIC);
                   if (ContextCompat.checkSelfPermission(context,Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},2);
                    }else{
                       takePicture();
                   }
                }

                break;
            //相册
            case R.id.btn_pick_photo:
                photoPopupwindow.dismiss();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//23
                    //Android6.0及以上，需要动态授予权限
                    // 验证所有权限是否都已经授权了
                    if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                        // TODO: Consider calling
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 3);
                        }

                    } else {
                        Intent openAlbumIntent = new Intent(
                                Intent.ACTION_GET_CONTENT);
                        openAlbumIntent.setType("image/*");
                        //用startActivityForResult方法，待会儿重写onActivityResult()方法，拿到图片做裁剪操作
                        startActivityForResult(openAlbumIntent, UPLOAD_PIC);

                        //  presenter.cardSelect(context);
                    }
                } else {
                    Intent openAlbumIntent = new Intent(
                            Intent.ACTION_GET_CONTENT);
                    openAlbumIntent.setType("image/*");
                    //用startActivityForResult方法，待会儿重写onActivityResult()方法，拿到图片做裁剪操作
                    startActivityForResult(openAlbumIntent, UPLOAD_PIC);

                    // presenter.cardSelect(context);
                }

                break;
            case R.id.txtQR:
                String qrCode = (String) SPUtils.get(context, SPConfig.QR_CODE,"");
                if (!TextUtils.isEmpty(qrCode)){
                    Intent intent=new Intent(context, ShareSqcodeActivity.class);
                    intent.putExtra("QRCODE",qrCode);
                    context.startActivity(intent);
                }
                break;
        }
    }

    private void takePicture(){
        String state = Environment.getExternalStorageState();
        if (state.equals(Environment.MEDIA_MOUNTED)) {
            File dir = new File(Environment.getExternalStorageDirectory() + "/");
            Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (!dir.exists()) {
                dir.mkdirs();
            }
            File file = new File(dir, "head.jpg");
            try{
                imageUri = Uri.fromFile(file);
                context.startActivityForResult(takePhotoIntent, PHOTO_GRAPH);

            }catch (Exception e){
                e.printStackTrace();
                Utils.showToast(context,"请从相册上传图片");
            }
        } else
            Toast.makeText(context, "未插入SD卡", Toast.LENGTH_SHORT).show();
    }

    @Override
    public MePresenter initPresenter() {
        return new MePresenter();
    }

    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (1 == requestCode) {
            presenter.takePictures(context);
        }
        if (2 == requestCode) {
            presenter.cardSelect(context);
        }
        if (3 == requestCode) {
            takePicture();
        }
    }

    @Override
    public void changeUIToLogout() {
        lineLay_not_login.setVisibility(View.VISIBLE);
        lineLay_login.setVisibility(View.GONE);
        messageQbv.setBadgeText(String.valueOf(0))
                .setGravityOffset(2, 2, true)
                .setBadgeTextSize(8, true)
                .hide(false);

        titleMessageQbv.setBadgeText(String.valueOf(0))
                .setGravityOffset(2, 2, true)
                .setBadgeTextSize(8, true)
                .hide(false);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        File file = new File("/sdcard/youjia/avatar/newhead.jpg");
        if (file.exists())
            file.delete();
    }

    @Override
    public void reloadGridAdapter(QuickAdapter<MeIcon> adapter) {
        gridView.setAdapter(adapter);
    }

    @Override
    public void changeUIToLogin(String nickName) {
        headPhoto.setImageDrawable(null);
        Picasso.with(context).load(FileUtils.rePath(ConfigValue.userInfo.getUrl())).placeholder(R.drawable.i_head_default).into(headPhoto);

        lineLay_not_login.setVisibility(View.GONE);
        ll_detail.setVisibility(View.VISIBLE);
        lineLay_login.setVisibility(View.VISIBLE);
        txtNickname.setText(nickName);

    }

    @Override
    public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
        checkTitle();
    }

    private void checkTitle(){
        if (checkIsVisible(context, mainTitle)) {
            mainTitle.setVisibility(View.VISIBLE);
            titleView.setVisibility(View.GONE);
        } else {
            mainTitle.setVisibility(View.GONE);
            titleView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == MainActivity.RESULT_OK) {
            switch (requestCode) {
                case TAKE_PICTURE:
                    cutImage(tempUri); // 对图片进行裁剪处理
                    break;
                case CHOOSE_PICTURE:
                    cutImage(data.getData()); // 对图片进行裁剪处理
                    break;
                case CROP_SMALL_PICTURE:
                    if (data != null) {
                        setImageToView(data); // 让刚才选择裁剪得到的图片显示在界面上
                    }
                    break;
                case UPLOAD_PIC:
                    Uri uri = data.getData();
                    presenter.doUpload(context, uri, new OnLoadListener() {
                        @Override
                        public void onLoad(Object content) {
                            if (content != null && content instanceof FileBean.Data){
                                FileBean.Data data = (FileBean.Data) content;
                                ConfigValue.userInfo.setUrl(data.getUrl());
                                if (data.getMallId() > 0){
                                    ConfigValue.userInfo.setFileId(String.valueOf(data.getMallId()));
                                }

                                Picasso.with(context).load(FileUtils.rePath(data.getUrl()))
                                        .placeholder(R.drawable.i_rect_bg)
                                        .into(headPhoto);
                            }
                        }
                    });
                    break;
                case PHOTO_GRAPH:
                    if (data != null){
                        Bundle b = data.getExtras();
                        Bitmap bitmap = (Bitmap) b.get("data");
                        bitmap = BitmapUtils.resizeBitmap(bitmap, 480);
                        headPhoto.setImageBitmap(bitmap);
                        presenter.doUpload(context, bitmap, new OnLoadListener() {
                            @Override
                            public void onLoad(Object content) {
                                if (content != null && content instanceof FileBean.Data){
                                    FileBean.Data data = (FileBean.Data) content;
                                    ConfigValue.userInfo.setUrl(data.getUrl());
                                    Picasso.with(context).load(FileUtils.rePath(data.getUrl()))
                                            .placeholder(R.drawable.i_rect_bg)
                                            .into(headPhoto);
                                }
                            }
                        });
                    }else{
                        Utils.showToast(context,"请从相册选择图片");
                    }

                    break;
            }
        }
    }

    /**
     * 裁剪图片方法实现
     */
    protected void cutImage(Uri uri) {
        if (uri == null) {
            Log.i("alanjet", "The uri is not exist.");
        }
        tempUri = uri;
        Intent intent = new Intent("com.android.camera.action.CROP");
        //com.android.camera.action.CROP这个action是用来裁剪图片用的
        intent.setDataAndType(uri, "image/*");
        // 设置裁剪
        intent.putExtra("crop", "true");
        // aspectX aspectY 是宽高的比例
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        // outputX outputY 是裁剪图片宽高
        intent.putExtra("outputX", 150);
        intent.putExtra("outputY", 150);
        intent.putExtra("return-data", true);
        startActivityForResult(intent, CROP_SMALL_PICTURE);
    }

    /**
     * 保存裁剪之后的图片数据
     */
    protected void setImageToView(Intent data) {
        Bundle extras = data.getExtras();
        if (extras != null) {
            mBitmap = extras.getParcelable("data");
            //这里图片是方形的，可以用一个工具类处理成圆形（很多头像都是圆形，这种工具类网上很多不再详述）
            headPhoto.setImageBitmap(mBitmap);//显示图片
            //在这个地方可以写上上传该图片到服务器的代码，后期将单独写一篇这方面的博客，敬请期待...
            if (filed_id==null){
                    presenter.doUpload(context, mBitmap,"0");
                }else {
                    presenter.doUpload(context, mBitmap,filed_id);
                }
        }
    }

    @Override
    public void onPause() {
        super.onPause();

        messageQbv.setBadgeText(String.valueOf(0))
                .setGravityOffset(2, 2, true)
                .setBadgeTextSize(8, true)
                .hide(false);

        titleMessageQbv.setBadgeText(String.valueOf(0))
                .setGravityOffset(2, 2, true)
                .setBadgeTextSize(8, true)
                .hide(false);
    }
}
